using System;
using System.Collections.Generic;
using System.Text;

namespace Xeml.Document.EnvironmentalOntology
{
    public class Min : TypeSpecifics
    {
        #region constructors
        public Min()
            : base()
        {
        }

        public Min(decimal value)
            : this()
        {
            base.NumberVal = value;
        }

        public Min(string value)
            : this()
        {
            base.TextVal = value;
        }

        public Min(DateTime value)
            : this()
        {
            base.DateVal = value;
        }

        public Min(bool value)
            : this()
        {
            base.BooleanVal = value;
        }
        #endregion constructors

        //private double numberVal;

        //public double NumberVal
        //{
        //    get { return numberVal; }
        //    set { numberVal = value; }
        //}

        //private DateTime dateVal;

        //public DateTime DateVal
        //{
        //    get { return dateVal; }
        //    set { dateVal = value; }
        //}



        public override bool Match(object value, VariableDataTypes baseType)
        {
            bool ret = false;
            switch (baseType)
            {
                case VariableDataTypes.Number:
                    {
                        try
                        {
                            decimal val = Convert.ToDecimal(value);
                            ret = this.NumberVal <= val;

                        }
                        catch (Exception)
                        {
                            ret = false;
                        }
                        break;
                    }
                case VariableDataTypes.Text:
                    {
                        ret = false;
                        break;
                    }
                case VariableDataTypes.Date:
                    {
                        if (value is DateTime)
                        {
                            DateTime val = (DateTime)value;
                            ret = this.DateVal <= val;
                        }
                        else
                            ret = false;
                        break;
                    }
                case VariableDataTypes.Bool:
                    {
                        ret = false;
                        break;
                    }
                default:
                    break;
            }
            return ret;
        }
    }

    public class Max : TypeSpecifics
    {
        #region constructors
        public Max()
            : base()
        {
        }

        public Max(decimal value)
            : this()
        {
            base.NumberVal = value;
        }

        public Max(string value)
            : this()
        {
            base.TextVal = value;
        }

        public Max(DateTime value)
            : this()
        {
            base.DateVal = value;
        }

        public Max(bool value)
            : this()
        {
            base.BooleanVal = value;
        }
        #endregion constructors

        //private double numberVal;

        //public double NumberVal
        //{
        //    get { return numberVal; }
        //    set { numberVal = value; }
        //}

        //private DateTime dateVal;

        //public DateTime DateVal
        //{
        //    get { return dateVal; }
        //    set { dateVal = value; }
        //}



        public override bool Match(object value, VariableDataTypes baseType)
        {
            bool ret = false;
            switch (baseType)
            {
                case VariableDataTypes.Number:
                    {
                        try
                        {
                            decimal val = Convert.ToDecimal(value);
                            ret = this.NumberVal >= val;
                        }
                        catch (Exception)
                        {
                            ret = false;
                        }
                        break;
                    }
                case VariableDataTypes.Text:
                    {
                        ret = false;
                        break;
                    }
                case VariableDataTypes.Date:
                    {
                        if (value is DateTime)
                        {
                            DateTime val = (DateTime)value;
                            ret = this.DateVal >= val;
                        }
                        else
                            ret = false;
                        break;
                    }
                case VariableDataTypes.Bool:
                    {
                        ret = false;
                        break;
                    }
                default:
                    break;
            }
            return ret;
        }
    }
}
